load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

package(default_visibility = ["//:__subpackages__"])

licenses(["notice"])

cc_library(
    name = "tink_config",
    srcs = ["tink_config.cc"],
    hdrs = ["tink_config.h"],
    include_prefix = "tink/config",
    visibility = ["//visibility:public"],
    deps = [
        "//:key_manager",
        "//:registry",
        "//daead:deterministic_aead_config",
        "//hybrid:hybrid_config",
        "//prf:prf_config",
        "//proto:config_cc_proto",
        "//signature:signature_config",
        "//streamingaead:streaming_aead_config",
        "//util:status",
        "@com_google_absl//absl/base:core_headers",
    ],
)

cc_library(
    name = "config_util",
    srcs = ["config_util.cc"],
    hdrs = ["config_util.h"],
    include_prefix = "tink/config",
    deps = ["//proto:config_cc_proto"],
)

bool_flag(
    name = "use_only_fips",
    build_setting_default = False,
)

cc_library(
    name = "tink_fips",
    srcs = ["tink_fips.cc"],
    hdrs = ["tink_fips.h"],
    include_prefix = "tink/config",
    visibility = ["//visibility:public"],
    deps = [
        "//internal:fips_utils",
        "//internal:registry_impl",
        "//util:status",
        "@boringssl//:crypto",
        "@com_google_absl//absl/base:core_headers",
    ],
)

cc_library(
    name = "global_registry",
    srcs = ["global_registry.cc"],
    hdrs = ["global_registry.h"],
    include_prefix = "tink/config",
    visibility = ["//visibility:public"],
    deps = [
        "//:configuration",
        "//:key_gen_configuration",
        "//internal:configuration_impl",
        "//internal:key_gen_configuration_impl",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "fips_140_2",
    srcs = ["fips_140_2.cc"],
    hdrs = ["fips_140_2.h"],
    include_prefix = "tink/config",
    visibility = ["//visibility:public"],
    deps = [
        "//:configuration",
        "//aead:aead_wrapper",
        "//aead:aes_ctr_hmac_aead_key_manager",
        "//aead:aes_gcm_key_manager",
        "//internal:configuration_impl",
        "//internal:fips_utils",
        "//mac:hmac_key_manager",
        "//mac:mac_wrapper",
        "//mac/internal:chunked_mac_wrapper",
        "//prf:hmac_prf_key_manager",
        "//prf:prf_set_wrapper",
        "//signature:ecdsa_sign_key_manager",
        "//signature:ecdsa_verify_key_manager",
        "//signature:public_key_sign_wrapper",
        "//signature:public_key_verify_wrapper",
        "//signature:rsa_ssa_pkcs1_sign_key_manager",
        "//signature:rsa_ssa_pkcs1_verify_key_manager",
        "//signature:rsa_ssa_pss_sign_key_manager",
        "//signature:rsa_ssa_pss_verify_key_manager",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "key_gen_fips_140_2",
    srcs = ["key_gen_fips_140_2.cc"],
    hdrs = ["key_gen_fips_140_2.h"],
    include_prefix = "tink/config",
    visibility = ["//visibility:public"],
    deps = [
        "//:key_gen_configuration",
        "//aead:aes_ctr_hmac_aead_key_manager",
        "//aead:aes_gcm_key_manager",
        "//internal:fips_utils",
        "//internal:key_gen_configuration_impl",
        "//mac:hmac_key_manager",
        "//prf:hmac_prf_key_manager",
        "//signature:ecdsa_sign_key_manager",
        "//signature:ecdsa_verify_key_manager",
        "//signature:rsa_ssa_pkcs1_sign_key_manager",
        "//signature:rsa_ssa_pkcs1_verify_key_manager",
        "//signature:rsa_ssa_pss_sign_key_manager",
        "//signature:rsa_ssa_pss_verify_key_manager",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "v0",
    srcs = ["v0.cc"],
    hdrs = ["v0.h"],
    include_prefix = "tink/config",
    tags = ["requires_boringcrypto_update"],
    deps = [
        "//:configuration",
        "//aead/internal:config_v0",
        "//daead/internal:config_v0",
        "//hybrid/internal:config_v0",
        "//internal:configuration_impl",
        "//mac/internal:config_v0",
        "//prf/internal:config_v0",
        "//signature/internal:config_v0",
        "//streamingaead/internal:config_v0",
        "@com_google_absl//absl/log:check",
    ],
)

cc_library(
    name = "key_gen_v0",
    srcs = ["key_gen_v0.cc"],
    hdrs = ["key_gen_v0.h"],
    include_prefix = "tink/config",
    tags = ["requires_boringcrypto_update"],
    deps = [
        "//:key_gen_configuration",
        "//aead/internal:key_gen_config_v0",
        "//daead/internal:key_gen_config_v0",
        "//hybrid/internal:key_gen_config_v0",
        "//mac/internal:key_gen_config_v0",
        "//prf/internal:key_gen_config_v0",
        "//signature/internal:key_gen_config_v0",
        "//streamingaead/internal:key_gen_config_v0",
        "@com_google_absl//absl/log:check",
    ],
)

# tests

cc_test(
    name = "tink_config_test",
    size = "small",
    srcs = ["tink_config_test.cc"],
    deps = [
        ":tink_config",
        "//:aead",
        "//:deterministic_aead",
        "//:hybrid_decrypt",
        "//:hybrid_encrypt",
        "//:mac",
        "//:registry",
        "//:streaming_aead",
        "//:tink_cc",
        "//aead:aes_gcm_key_manager",
        "//util:status",
        "//util:test_matchers",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "config_util_test",
    size = "small",
    srcs = ["config_util_test.cc"],
    deps = [
        ":config_util",
        "//proto:config_cc_proto",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "tink_fips_test",
    size = "small",
    srcs = ["tink_fips_test.cc"],
    tags = ["fips"],
    deps = [
        ":tink_fips",
        "//:registry",
        "//aead:aead_config",
        "//internal:fips_utils",
        "//util:status",
        "//util:test_matchers",
        "@boringssl//:crypto",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "global_registry_test",
    srcs = ["global_registry_test.cc"],
    deps = [
        ":global_registry",
        "//:core/key_type_manager",
        "//:core/template_util",
        "//:input_stream",
        "//:keyset_handle",
        "//:primitive_set",
        "//:primitive_wrapper",
        "//:registry",
        "//proto:aes_gcm_cc_proto",
        "//proto:tink_cc_proto",
        "//util:status",
        "//util:statusor",
        "//util:test_matchers",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "fips_140_2_test",
    srcs = ["fips_140_2_test.cc"],
    deps = [
        ":fips_140_2",
        ":key_gen_fips_140_2",
        "//:aead",
        "//:chunked_mac",
        "//:keyset_handle",
        "//:mac",
        "//:public_key_sign",
        "//:public_key_verify",
        "//aead:aead_key_templates",
        "//aead:aes_ctr_hmac_aead_key_manager",
        "//aead:aes_gcm_key_manager",
        "//internal:configuration_impl",
        "//internal:fips_utils",
        "//internal:key_type_info_store",
        "//internal:keyset_wrapper_store",
        "//mac:aes_cmac_key_manager",
        "//mac:hmac_key_manager",
        "//prf:hmac_prf_key_manager",
        "//prf:prf_set",
        "//signature:ecdsa_verify_key_manager",
        "//signature:rsa_ssa_pkcs1_verify_key_manager",
        "//signature:rsa_ssa_pss_verify_key_manager",
        "//util:statusor",
        "//util:test_matchers",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "key_gen_fips_140_2_test",
    srcs = ["key_gen_fips_140_2_test.cc"],
    deps = [
        ":key_gen_fips_140_2",
        "//:keyset_handle",
        "//aead:aead_key_templates",
        "//aead:aes_ctr_hmac_aead_key_manager",
        "//aead:aes_gcm_key_manager",
        "//internal:fips_utils",
        "//internal:key_gen_configuration_impl",
        "//internal:key_type_info_store",
        "//mac:aes_cmac_key_manager",
        "//mac:hmac_key_manager",
        "//prf:hmac_prf_key_manager",
        "//signature:ecdsa_verify_key_manager",
        "//signature:rsa_ssa_pkcs1_verify_key_manager",
        "//signature:rsa_ssa_pss_verify_key_manager",
        "//util:statusor",
        "//util:test_matchers",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "v0_test",
    srcs = ["v0_test.cc"],
    tags = ["requires_boringcrypto_update"],
    deps = [
        ":key_gen_v0",
        ":v0",
        "//:aead",
        "//:chunked_mac",
        "//:configuration",
        "//:deterministic_aead",
        "//:hybrid_decrypt",
        "//:hybrid_encrypt",
        "//:keyset_handle",
        "//:mac",
        "//:public_key_sign",
        "//:public_key_verify",
        "//:streaming_aead",
        "//aead:aead_key_templates",
        "//aead:aes_ctr_hmac_aead_key_manager",
        "//aead:aes_eax_key_manager",
        "//aead:aes_gcm_key_manager",
        "//aead:aes_gcm_siv_key_manager",
        "//aead:xchacha20_poly1305_key_manager",
        "//daead:aes_siv_key_manager",
        "//hybrid:ecies_aead_hkdf_public_key_manager",
        "//hybrid/internal:hpke_public_key_manager",
        "//internal:configuration_impl",
        "//internal:key_gen_configuration_impl",
        "//internal:key_type_info_store",
        "//internal:keyset_wrapper_store",
        "//mac:aes_cmac_key_manager",
        "//mac:hmac_key_manager",
        "//prf:aes_cmac_prf_key_manager",
        "//prf:hkdf_prf_key_manager",
        "//prf:hmac_prf_key_manager",
        "//prf:prf_set",
        "//signature:ecdsa_verify_key_manager",
        "//signature:ed25519_verify_key_manager",
        "//signature:rsa_ssa_pkcs1_verify_key_manager",
        "//signature:rsa_ssa_pss_verify_key_manager",
        "//streamingaead:aes_ctr_hmac_streaming_key_manager",
        "//streamingaead:aes_gcm_hkdf_streaming_key_manager",
        "//util:statusor",
        "//util:test_matchers",
        "@com_google_googletest//:gtest_main",
    ],
)
